package com.example.venue_reservation_service.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.venue_reservation_service.domain.Price;
import com.example.venue_reservation_service.mapper.PriceMapper;
import com.example.venue_reservation_service.service.PriceService;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
* @author 31586
* @description 针对表【venue_price】的数据库操作Service实现
* @createDate 2024-11-13 11:22:13
*/
@Service
public class PriceServiceImpl extends ServiceImpl<PriceMapper, Price>
    implements PriceService{

    @Override
    public Double getPrice(Integer venueId) {
        return getOne(Wrappers.<Price>lambdaQuery()
                .eq(Price::getVenueId, venueId))
                .getPrice();
    }

    @Override
    public void updatePrice(Price price) {
        Price one = getOne(Wrappers.<Price>lambdaQuery().eq(Price::getVenueId, price.getVenueId()));
        if (Optional.ofNullable(one).isEmpty()) {
            // 无场地相关费用信息，则进行创建
            save(price);
        }else {
            one.setPrice(price.getPrice());
            updateById(one);
        }
    }
}




